package de.gbeine.java.ebookmanager.tag;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.yaml.snakeyaml.Yaml;

public class TagFactory {

    /**
     *
     * @param pInput
     * @return
     */
	public static Tag fromStream(final InputStream pInput) {
	    Yaml yaml = new Yaml(new TagConstructor());
	    return (Tag) yaml.load(pInput);
	}

	/**
	 *
	 * @param pFile
	 * @return
	 */
	public static Tag fromFile(final File pFile) {
	    final Tag tag;
	    try {
	        InputStream input = new FileInputStream(pFile);
	        tag = TagFactory.fromStream(input);
	    } catch (FileNotFoundException ex) {
	        throw new IllegalArgumentException(ex);
	    }
	    return tag;
	}

	/**
	 *
	 * @param pFileName
	 * @return
	 */
    public static Tag fromFile(final String pFileName) {
        return TagFactory.fromFile(new File(pFileName));
    }
}
